package com.bxmdm.ragdemo.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName MCPController
 * @Description
 * @Author li
 * @Time 2025/4/24 16:46
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/ai/mcp")
@Tag(name = "mcp demo")
public class MCPController {

    @Autowired
    private OllamaChatModel ollamaChatModel;

    private final ChatClient chatClient;

    public MCPController(ChatClient.Builder builder, ToolCallbackProvider tools) {
        this.chatClient = builder
                .defaultTools(tools)
                .build();
    }

    @GetMapping("/chat")
    public String chat(@RequestParam(value = "msg", defaultValue = "今天天气如何？") String msg) {
        String result = ollamaChatModel.call(msg);
        String result1 = chatClient.prompt().user(msg).call().content();
        String response = "no mcp:" + result + "\n mcp:" + result1;
        System.out.println("响应结果: " + response);
        return response;
    }
}
